package com.bop.dehong.huodong;

import java.util.ArrayList;
import java.util.List;

import com.base.dehong.http.RequestCallBack;
import com.base.dehong.util.ToastUtils;
import com.bop.dehong.R;
import com.bop.dehong.base.DeHongApp;
import com.bop.dehong.base.TopManager;
import com.bop.dehong.config.Config;
import com.bop.dehong.http.model.GetHuodongModel;
import com.bop.dehong.info.GetHuodongInfo;
import com.bop.dehong.login.LoginActivity;
import com.bop.dehong.main.BottomBarActivity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.View;
/**
 * 活动列表
 * @author YeFengyun
 *
 */
public class HuodongActivity extends BottomBarActivity{
	private List<Fragment> mFragments = new ArrayList<Fragment>();
	private HuodongSpecialFragment mSpecialFragment;
	private HuodongRewardFragment mRewardFragment;
	private HuodongEndFragment mEndFragment;
	
	private GetHuodongModel mGetModel;
	
	private int mType = 0, mPage;
	
	@Override
	protected List<Fragment> getFragments() {
		return mFragments;
	}

	@Override
	protected List<View> getBottomViews() {
		List<View> views = new ArrayList<View>();
		views.add(getView(R.id.special));
		views.add(getView(R.id.reward));
		views.add(getView(R.id.end));
		return views;
	}
	
	

	@Override
	protected void initTop() {
		super.initTop();
		View mView = getView(R.id.top);
		TopManager manager = new TopManager(mView);
		manager.setTitle(R.string.huodong_list);
		manager.setLeftImageVisibility(View.VISIBLE);
		
	}
	public void reqData(int type,int page){
		if (mGetModel == null) {
			mGetModel = new GetHuodongModel(this, callback);
		}
		mType = type;
		mPage = page;
		String uid = DeHongApp.mLoginEntity.uid;
		if (TextUtils.isEmpty(uid))
		{
			ToastUtils.show(this, "你还未登录，请先登录！");
			Intent intent = new Intent(this, LoginActivity.class);
			intent.putExtra(Config.GO_BACK, true);
			startActivityForResult(intent, 100);
			return;
		}
		showProgressDialog();
		mGetModel.doNet(uid, type+"", page+"");
	}
	RequestCallBack<GetHuodongInfo> callback = new RequestCallBack<GetHuodongInfo>() {

		@Override
		public void end() {
			disappearProgressDialog();
		}

		@Override
		public void onSuccess(GetHuodongInfo info) {
			super.onSuccess(info);
			if (mType == 0) {
				mRewardFragment.initData(info);
			}else if (mType == 1) {
				mSpecialFragment.initData(info);
			}else if (mType == 2) {
				mEndFragment.initData(info);
			}
		}
		
	};

	@Override
	protected void initFragments() {
		mSpecialFragment = new HuodongSpecialFragment();
		mRewardFragment = new HuodongRewardFragment();
		mEndFragment = new HuodongEndFragment();

		mFragments.add(mSpecialFragment);
		mFragments.add(mRewardFragment);
		mFragments.add(mEndFragment);
	}

	@Override
	protected int getContentViewId() {
		return R.layout.activity_huodong_list;
	}

	@Override
	protected void onActivityResult(int arg0, int resultCode, Intent arg2) {
		super.onActivityResult(arg0, resultCode, arg2);
		if (resultCode != RESULT_OK) {
			finishCurrentActivity();
			return;
		}
		reqData(mType, mPage);
	}
}
